package com.newtouch.bxzs.business.message.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newtouch.bxzs.common.base.model.NotificationUserMap;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 通知信息的返回参数Mapper接口
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月14日</td>
 * <td>liman</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author liman
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface NotificationUserMapMapper extends BaseMapper<NotificationUserMap> {


    /**
     * 批量插入
     *
     * @param list 数据
     */
    void saveBatch(@Param("list") List<NotificationUserMap> list);

    /**
     * 修改消息的阅读状态为已读
     *
     * @param notificationId 消息id
     * @param userId         用户id
     */
    @Update("UPDATE ASSISTANT_NOTIFICATION_USER_MAP SET IS_READ = 1 WHERE USER_ID = #{userId} AND NOTIFICATION_ID = #{notificationId}")
    void modifyReadStatus(@Param("notificationId") String notificationId, @Param("userId") String userId);

    /**
     * 根据消息id查询接收人id
     *
     * @param notificationId 消息id
     * @return 接收人id集合
     */
    @Select("SELECT USER_ID FROM ASSISTANT_NOTIFICATION_USER_MAP WHERE NOTIFICATION_ID = #{notificationId}")
    List<String> listUserIdByNotificationId(@Param("notificationId") String notificationId);

    /**
     * 根据通知id和用户id删除
     * @param notificationId 通知id
     * @param userId 用户id
     */
    @Delete("UPDATE ASSISTANT_NOTIFICATION_USER_MAP SET IS_DELETE = 1 WHERE NOTIFICATION_ID = #{notificationId} AND USER_ID = #{userId}")
    void deleteByNotificationIdAndUserId(@Param("notificationId") String notificationId, @Param("userId") String userId);
}
